$(document).ready(function(){
	
	$(".profileTab").click(function(){
	
		allProfileTabsClosed();
		$(this).parent().addClass("tabOpen");
		
		//HIDE CONTENT
		
		
		//$("#loadingTab").show();
		//$("#homeTabContent").hide();
		
		var tabClass = $(this).text().replace(" ", "");
		
		var delay = function() { displayProfileTabContent(tabClass); };
			
		setTimeout(delay, 800);
		
	});
	
	function allProfileTabsClosed()
	{
		$("#profileTabs > span").removeClass("tabOpen");
	}
	
	$("#unfollowUser").mouseover(function(){
		$(this).text("Unfollow");
	});
	
	$("#unfollowUser").mouseout(function(){
		$(this).text("Following");
	});	
	
	//######## FOLLOW & UNFOLLOW ###########
	
	//UNFOLLOW
	$("#unfollowUser").click(function(){
	
		var unfollowBtnClass = $(this).attr('class').split(' ');
		var uid = unfollowBtnClass[1];
	
		$.ajax({
			type: "POST",
			url: "../php/ajax/profile/followUnfollow.php",
			data: "t=unfollow&uid=" + uid,
			success: function(obj)
			{
				if(obj == "1"){
					$("#unfollowUser").hide();
					$("#followUser").show();
				} else {
					alert('Error unfollowing');
				}
			}
		});
	});
	
	//FOLLOW
	$("#followUser").click(function(){
	
		var followBtnClass = $(this).attr('class').split(' ');
		var uid = followBtnClass[1];
	
		$.ajax({
			type: "POST",
			url: "../php/ajax/profile/followUnfollow.php",
			data: "t=follow&uid=" + uid,
			success: function(obj)
			{
				if(obj == "1"){
					$("#followUser").hide();
					$("#unfollowUser").show();
				} else {
					alert('Error following');
				}
			}
		});
	});
	
});

function displayProfileTabContent(tabClass)
{
	//$.ajax({
		//type: "POST",
		//url: "php/ajax/home/tabContent.php",
		//data: "t=" + tabClass,
		//success: function(obj)
		//{
			//var json = JSON.parse(obj);
			
			//SHOW CONTENT
			//$("#homeNewsHeading").text(json.heading);
			
			
			//$("#loadingTab").hide();
			//$("#homeTabContent").show();
		//}
	//});
}


